package com.tongji.showroom.model
{ 
	import com.adobe.serialization.json.JSON;
	import com.tongji.showroom.vo.ObjectTranslator;
	import com.tongji.showroom.vo.Type;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	
	import org.robotlegs.mvcs.Actor;
	
	/**
	 * 
	 * @author jiarong
	 * 
	 */
	
	[Bindable]
	public class TypeModel extends Actor
	{
		public var placeArray:String;
		public var styleArray:String;
		public var placeCollection:ArrayCollection;
		public var styleCollection:ArrayCollection;
		
		
		public function TypeModel()
		{
			super();
		}
		
		//更新场地数据
		public function updatePlaces(placeArray:String):void
		{
			this.placeArray = placeArray;
			var arr:Array = (JSON.decode(placeArray) as Array);
			var tempArr:Array = new Array();
			for (var i:int = 0; i < arr.length; i++)
			{
				var obj:Object = arr[i] as Object;
				var type:Type = ObjectTranslator.objectToInstance(obj, Type) as Type;
				tempArr.push(type);
			}
			placeCollection = new ArrayCollection(tempArr);
		}
		
		//更新风格数据
		public function updateStyles(style:String):void
		{
			this.styleArray = style;
			var arr:Array = (JSON.decode(styleArray) as Array);
			var tempArr:Array = new Array();
			for (var i:int = 0; i < arr.length; i++)
			{
				var obj:Object = arr[i] as Object;
				var type:Type = ObjectTranslator.objectToInstance(obj, Type) as Type;
				tempArr.push(type);
			}
			styleCollection = new ArrayCollection(tempArr);
		}
	}
}